package com.peng.leetcode.sort;

/**
 * Merge
 * 面试题 10.01. 合并排序的数组
 * https://leetcode.cn/problems/sorted-merge-lcci/
 *
 * @author: lupeng6
 * @create: 2023/3/21 19:32
 */
public class Merge {

    public static void main(String[] args) {
        int[] a = {0};
        new Merge().merge(a, 0, new int[]{1}, 1);
        for (int i : a) {
            System.out.println(i);
        }
    }

    public void merge(int[] A, int m, int[] B, int n) {
        int i = m - 1;
        int j = n - 1;
        int index = A.length - 1;
        while (j >= 0) {
            if (i >= 0 && A[i] > B[j]) {
                A[index] = A[i];
                i--;
            } else {
                A[index] = B[j];
                j--;
            }
            index--;
        }
    }
}
